﻿using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using WeakReferenceDemo;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            var param = new MyStruct() { X = 3 };
            Change(ref param);
            Console.WriteLine(param.X);
            TestReturn();
            // Test(param);
            //Console.WriteLine($"x={param.X}");
            //int num = 0;
            //Test2(out num);
            //Console.WriteLine($"num={num}");
            //try
            //{
            //    throw new Exception();
            //}
            //catch
            //{

            //}
            object str = "hello";
            //char[] values = { 'h', 'e', 'l', 'l', 'o' };
            object str2 = "hello";
           // object str2 = new string(values); 
            Console.WriteLine("Using Equality operator: {0}", str == str2);
            Console.WriteLine("Using equals() method: {0}", str.Equals(str2));
            var list = new List<string> { "1", "2" };
            //foreach(var l in list)
            //{
            //    list.Remove(l);
            //}

            var mytest1 = new MyClass { X = 1 };
            var mytest2 = new MyClass { X=1};
            var mytest3 = mytest1 + mytest2;
            Console.WriteLine("test Equality operator: {0}", mytest1 == mytest2);
            Console.WriteLine("test equals() method: {0}", mytest1.Equals(mytest2));//false,如果内部进行重写，可以为true

            var mystructtest1 = new MyStruct { X = 1 };
            var mystructtest2 = new MyStruct { X = 1 };
            //Console.WriteLine("mystructtest Equality operator: {0}", mystructtest1 == mystructtest2);//值类型无法用==
            Console.WriteLine("mystructtest equals() method: {0}", mystructtest1.Equals(mystructtest2));//equals只比较两者的值。

            for (int i = 0; i < list.Count; i++)
            {
                string l = list[i];
                list.Remove(l);
            }
            Console.ReadLine();
        }

       
        static void Change(ref MyStruct param2)
        {
            //不使用ref时候，值类型不会改变，使用ref时，传递的栈引用是同一个
            param2=new MyStruct();
            param2.X = 4;
           // param2 = new MyClass { X = 4 };
        }

        private static void Test(MyClass myClass)
        {
            myClass.X = 4;
        }

        private static void Test2(out int num)
        {
            num = 120;
            num = num / 2;
            Console.WriteLine($"numInternal={num}");
        }

        private static bool TestReturn()
        {
            return true;
        }
    }
}
